package com.sto.stoapp.thread;

import android.content.Context;
import android.os.Handler;

import com.sto.stoapp.activity.R;
import com.sto.stoapp.manager.BlueWeigthManager;

/**
 * UI蓝牙连接线程
 * 
 * @author mgf
 * 
 */
public class BlueReadThread extends BaseThread {

	private BlueWeigthManager bluemanager;

	/**
	 * 构造函数
	 * 
	 * @param context
	 *            上下文
	 * @param handler
	 *            媒介
	 * @param address
	 *            mac地址
	 * @param isShowing
	 *            是否显示进度圈
	 */
	public BlueReadThread(Context context, Handler handler, String address,
			boolean isShowing) {
		super(context);
		bluemanager = new BlueWeigthManager(context, handler, address);
		if (isShowing) {
			showDialogByMessage(context.getText(R.string.now_connect_blue)
					.toString());
		}
	}

	@Override
	public void run() {
		super.run();
		try {
			Thread.sleep(2000);
			// 防止还没连接直接退出
			if (bluemanager != null) {
				bluemanager.connect();
			}
		} catch (InterruptedException e) {
			e.printStackTrace();
		}
	}

	public void clearBlueDevices() {
		if (bluemanager != null) {
			bluemanager.cancelConnect();
		//	bluemanager = null;
		}
	}

	public boolean isConnected() {
		if (bluemanager != null)
			return bluemanager.getIsconnect();
		return false;
	}
	

}
